package com.shenmazong.thread;

/**
 * @program: server-java-demo
 * @description: synchronizedTest
 * @author: 亮子说编程
 * @create: 2020-10-20 15:33
 **/
public class SynchronizedTest4 implements Runnable {

    //共享资源
    static int i =0;
    /**
     * synchronized 修饰实例方法
     */
    public static synchronized void increase(){
        i++;
    }
    @Override
    public void run(){
        for (int j =0 ; j<10000;j++){
            increase();
        }
        System.out.println(Thread.currentThread().getName()+" finish.");
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new SynchronizedTest4());
        Thread t2 = new Thread(new SynchronizedTest4());
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(i);
    }
}
